using System;
using System.Data;
using System.Collections;
using CE.Database;
/// <summary>
/// Summary description for UserProfileDB
/// </summary>
/// 
namespace CE.CarInsurance
{
    public class CarClaimHistoryDB
    {
        public CarClaimHistoryDB()
        {
            //
            // TODO: Add constructor logic here
            //
        }

        public Int64 Insert(CarClaimHistory carhis)
        {
            MyDatabase _db = new MyDatabase();
            Int64 _result = -1;
            string _spName = "sprocCarClaimHistoryInsertUpdateSingleItem";
            
            SortedList _sPara = new SortedList();
            
            #region Parameter
                _sPara.Add("@CarClaimID", carhis.CarClaimId);
                _sPara.Add("@CECarId", carhis.CECarId);
                _sPara.Add("@NOCLast3", carhis.NoOfClaimInLast3Year );
                _sPara.Add("@NOCLast3Value", carhis.Last3YearClaimValue);
                _sPara.Add("@NOCLast2", carhis.NoOfClaimInLast2Year);
                _sPara.Add("@NOCLast2Value", carhis.Last2YearClaimValue);
                _sPara.Add("@NOCLast1", carhis.NoOfClaimInLast1Year);
                _sPara.Add("@NOCLast1Value", carhis.Last1YearClaimValue);
                _sPara.Add("@RefCEUserId", carhis.RerCEUserId);
                _sPara.Add("@ViewedDetailId", carhis.ViewedDetailId);
                _sPara.Add("@Status", carhis.Status);
                _sPara.Add("@Info1", carhis.Info1);
                _sPara.Add("@Info2", carhis.Info2);
                _sPara.Add("@Info3", carhis.Info3);
                _sPara.Add("@Info4", carhis.Info4);
                _sPara.Add("@Info5", carhis.Info5);
                _sPara.Add("@Info6", carhis.Info6);
                _sPara.Add("@Info7", carhis.Info7);
                _sPara.Add("@Info8", carhis.Info8);
                _sPara.Add("@Info9", carhis.Info9);
                _sPara.Add("@Info10", carhis.Info10);
            #endregion

            _result = _db.ExecuteSP(_spName, _sPara);

            return _result;
        }

        public bool Update()
        {
            return true;
        }

        public bool Delete()
        {
            return true;
        }

        public CarClaimHistory GetCarClaimHistory(Int64 CarClaimId)
        {
            CarClaimHistory _carhis = null;
            MyDatabase _db = new MyDatabase();
            string _spName = "sprocCarClaimHistorySelectSingleItem";

            SortedList _spara = new SortedList();
            _spara.Add("@CarClaimId", CarClaimId);

            using (DataTable _dt = _db.GetDataTableBySP(_spName, _spara))
            {
                if (_dt != null && _dt.Rows.Count > 0)
                {
                    _carhis = new CarClaimHistory();
                    _carhis = FillDataRecord(_dt);
                }
            }
            return _carhis;
        }

        public CarClaimHistory GetCarClaimHistory(Int64 CarId, Int64 UserId)
        {
            CarClaimHistory _carhis = null;
            MyDatabase _db = new MyDatabase();
            string _spName = "sprocCarClaimHistoryByCarIdSelectSingleItem";

            SortedList _spara = new SortedList();
            _spara.Add("@CECarId", CarId);
            _spara.Add("@RefCEUserId", UserId);

            using (DataTable _dt = _db.GetDataTableBySP(_spName, _spara))
            {
                if (_dt != null && _dt.Rows.Count > 0)
                {
                    _carhis = new CarClaimHistory();
                    _carhis = FillDataRecord(_dt);
                }
            }
            return _carhis;
        }

        public bool UpdateStatus(Int64 CarClaimHistoryId)
        {
            MyDatabase _db = new MyDatabase();
            string strSQL = "Update tblCarClaimHistory Set Status = 'InActive' Where CarClaimId = @CarClaimId;";
            int _result = 0;
            SortedList _sPara = new SortedList();

            _sPara.Add("@CarClaimId", CarClaimHistoryId);

            _result = _db.ExecuteNonSqlStatement(strSQL, _sPara);
            return _result > 0;
        }

        private CarClaimHistory FillDataRecord(DataTable myDataTable)
        {
            CarClaimHistory myClaimHistory = new CarClaimHistory();
            myClaimHistory.CECarId = Convert.ToInt64(myDataTable.Rows[0]["CECarID"].ToString());
            myClaimHistory.CarClaimId = Convert.ToInt64(myDataTable.Rows[0]["CarClaimId"].ToString());
            myClaimHistory.NoOfClaimInLast3Year = Convert.ToByte(myDataTable.Rows[0]["NOCLast3"].ToString());
            myClaimHistory.NoOfClaimInLast2Year = Convert.ToByte(myDataTable.Rows[0]["NOCLast2"].ToString());
            myClaimHistory.NoOfClaimInLast1Year = Convert.ToByte(myDataTable.Rows[0]["NOCLast1"].ToString());
            myClaimHistory.Last3YearClaimValue = myDataTable.Rows[0]["NOCLast3Value"].ToString();
            myClaimHistory.Last2YearClaimValue = myDataTable.Rows[0]["NOCLast2Value"].ToString();
            myClaimHistory.Last1YearClaimValue = myDataTable.Rows[0]["NOCLast1Value"].ToString();
            myClaimHistory.RerCEUserId = Convert.ToInt64(myDataTable.Rows[0]["RefCEUserId"].ToString());
            myClaimHistory.Status = myDataTable.Rows[0]["Status"].ToString();
            return myClaimHistory;
        }
        
    }
}